package com.zhengke.controller.hubf;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.codec.language.bm.Lang;
import org.springframework.beans.factory.annotation.Autowired;
/**
 * 代发货列表统计信息
 */
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zhengke.pojo.AjaxResult;
import com.zhengke.pojo.ShippingEntity;
import com.zhengke.pojo.SysOrderResult;
import com.zhengke.service.ShippingListDaoService;

@Controller
@RequestMapping("/shipping")
public class ShippingListController {
	
	@Autowired
	ShippingListDaoService shipingService;

	
	@RequestMapping("/gotoShippingJsp.do")
	public String goToShippingJsp() {
		return "/shipping/shippingList";
	}
	
	@RequestMapping("/getShippingList.do")
	@ResponseBody
	public SysOrderResult getShippingList(String order_sn,String user_id,String user_name,String user_card_number,String receiver_phone,String leftAdd_time,String rightAdd_time,int page ,int limit) throws Exception {
		PageHelper.startPage(page,limit, true);
		System.err.println("order_sn==>"+order_sn+"user_id==>"+user_id+"user_name==>"+user_name+"user_card_number==>"+user_card_number+"receiver_phone==>"+receiver_phone+"leftAdd_time==>"+"rightAdd_time==>"+rightAdd_time+"page===>"+page+"limit===>"+limit);
		try {
			Map<String,Object> messageMap = new HashMap<String, Object>();
			//将从前台获取到的信息进行封装
			messageMap.put("order_sn", order_sn);
			messageMap.put("user_id", user_id);
			messageMap.put("user_name", user_name);
			messageMap.put("receiver_phone", receiver_phone);
			messageMap.put("user_card_number", user_card_number);
			messageMap.put("leftAdd_time", leftAdd_time);
			messageMap.put("rightAdd_time", rightAdd_time);
			List<ShippingEntity> shippingListReList = shipingService.getShippingList(messageMap);
			//System.out.println(shippingListReList.size());
			PageInfo<ShippingEntity> pageinotInfo = new PageInfo<ShippingEntity>(shippingListReList);
			//System.out.println("<========================>"+pageinotInfo.getTotal());
			SysOrderResult	sysOrderResult = new SysOrderResult();
			sysOrderResult.setCode("0");
			String totela = shipingService.querryOrderTotal();
			long totalLang = Long.parseLong(totela);
			sysOrderResult.setCount(totalLang); 
			sysOrderResult.setData(shippingListReList);
			return sysOrderResult;
		}catch(Exception e) {
			return null;
		}
		
	}
	
	@RequestMapping("/updateOrder.do")
	@ResponseBody
	public AjaxResult updateOrderMethod(String id) {
		
		System.out.println("---------------`````````````````````````--------------------"+id);
		
		int result = shipingService.updateOrderMethod(id);
		
		if(result == 1) {
			return new AjaxResult("200","更新成功！！");
		}else {
			return new AjaxResult("300","更新失败！！");
		}
	}
}
